use serde_derive::Deserialize;
use std::collections::HashMap;

use serde::Serialize;
use serde_json::{Value, json};

use super::my_cache;
use super::my_err::MyErr;

// 客运达 接口
#[derive(Deserialize)]
pub struct Bus365 {
    pub domain: String,
    pub tenantcode: String,
    pub username: String,
    pub password: String,
}

impl Bus365 {
     
}

async fn post_from_data_to_url<T: Serialize + std::fmt::Debug + ?Sized>(url: &str, form_data: &T) -> Result<Value, MyErr> {
    log::info!("\n\n\n url:{} data:{:?} \n\n\n\n", url, form_data);

    let client = reqwest::Client::new();
    let rs = client.post(url).form(form_data).send().await;
     println!("\n\n\n\n {:?} \n\n\n\n", rs);
    match rs {
        Ok(res) => match res.json::<serde_json::Value>().await {
            Ok(v) => Ok(v),
            Err(e) => {
                log::error!("读取URL数据失败！错误：{:?} url:{} post_form_data:{:?}", e, url, form_data);
                Err(MyErr::Msg("网络异常！".to_string()))
            }
        },
        Err(e) => {
            log::error!("连接url地址失败！错误：{:?} url:{} post_form_data:{:?}", e, url, form_data);
            Err(MyErr::Msg("网络异常！".to_string()))
        }
    }
}
